﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DTO;
using BUS;

public partial class ChiTietSanPham : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        lbthongbao.Visible = false;
        String ID = Request.QueryString["ID"];
        SanPhamDTO sanpham = SanPhamBUS.LaySanPhamTheoID(int.Parse(ID));
        HangSanXuatDTO hangsanxuat = HangSanXuatBUS.LayHangSanXuatTheoID(sanpham.MaHangSanXuat);

        TenSanPham.Text = sanpham.TenSanPham;
        NhaSanXuat.NavigateUrl = ("SanPhamTheoNhaSanXuat.aspx?ID=" + sanpham.MaHangSanXuat.ToString());
        NhaSanXuat.Text = hangsanxuat.TenHangSanXuat;
        ImageSanPham.ImageUrl = "~/Image/" + sanpham.HinhSanPham;
        
        GiaSanPham.Text = sanpham.GiaBanHienTai.ToString() + "  .VND";

        ChiTietDienThoaiDTO dienthoai = ChiTietDienThoaiBUS.LayChiTietDienThoaiTheoMaSanPham(sanpham.ID);

        TanSo.Text = dienthoai.TanSo;
        KieuDang.Text = dienthoai.KieuDang;
        KichThuoc.Text = dienthoai.KichThuoc;
        TrongLuong.Text = dienthoai.TrongLuong;
        ThongTinManHinh.Text = dienthoai.ThongTinManHinh;
        KichThuocManHinh.Text = dienthoai.KichThuocManHinh;
        DoPhanGiaiManHinh.Text = dienthoai.DoPhanGiaiManHinh;
        KieuChuong.Text = dienthoai.KieuChuong;
        if (dienthoai.Rung == true)
            Rung.Text = "Có";
        else
            Rung.Text = "Không";
        SoLuongDanhBa.Text = dienthoai.SoLuongDanhBa;
        NhatKyCuocGoi.Text = dienthoai.NhatKyCuocGoi;
        DungLuongBoNhoTrong.Text = dienthoai.DungLuongBoNhoTrong;
        DungLuongBoNhoNgoaiHoTro.Text = dienthoai.DungLuongBoNhoNgoaiHoTro;
        TinNhan.Text = dienthoai.TinNhan;
        CacKieuKetNoi.Text = dienthoai.CacKieuKetNoi;
        Camera.Text = dienthoai.Camera;
        Pin.Text = dienthoai.Pin;
        ThoiGianCho.Text = dienthoai.ThoiGianCho;
        ThoiGianThoai.Text = dienthoai.ThoiGianThoai;
        ThongTinBaoHanh.Text = dienthoai.ThongTinBaoHanh;
        if (dienthoai.NhomDienThoai == 1)
            NhomDienThoai.Text = "Điện thoại thường";
        else
            NhomDienThoai.Text = "Điện thoại thông minh";
        TrangChu.Text = hangsanxuat.URL.ToString();
        TrangChu.NavigateUrl = hangsanxuat.URL.ToString();

        List<GianHangDTO> listGianHang = new List<GianHangDTO>();

        List<SanPhamThuongDangBanTrenGianHangDTO> listspthuong = SanPhamThuongDangBanTrenGianHangBUS.LayDanhSachSanPhamThuongTheoMaSanPham(int.Parse(ID));
        foreach (SanPhamThuongDangBanTrenGianHangDTO spthuong in listspthuong)
        {
            if (BUS.GianHangBUS.LayGianHangTheoID(spthuong.MaGianHang).TinhTrang == true)
                listGianHang.Add(BUS.GianHangBUS.LayGianHangTheoID(spthuong.MaGianHang));
        }
        if (listGianHang.Count == 0)
        {
            lbthongbao.Visible = true;
        }        
        CollectionPager2.PageSize = 9;
        CollectionPager2.DataSource = listGianHang;
        CollectionPager2.BindToControl = dtlGianHang;
        dtlGianHang.DataSource = CollectionPager2.DataSourcePaged;        
    }

}
